<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="frm.ssh.util.page.SearchBean"%>
<%@ include file="/jsp/common/common.jsp"%>

<html>
	<head>
		<script language="javascript" src="<%=contextPath%>/js/func.js"type=""></script>
		<script type="text/javascript" src="<%=contextPath%>/ext3/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/ext3/ext-all.js"></script>
		<link rel="stylesheet" type="text/css"	href="<%=contextPath%>/ext3/resources/css/ext-all.css">
		<script>
		
		String.prototype.endWith=function(str){
		if(str==null||str==""||this.length==0||str.length>this.length)
			return false;
		if(this.substring(this.length-str.length)==str)
			return true;
		else
			return false;
		return true;
		}
		
			Ext.onReady(function(){
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				         {
				            text: '选择',
				            icon:"<%=contextPath%>/images/pass.gif",
				            handler:setParentMany
				        },'-', 
				        {
				            text: '查询',
				            icon:"<%=contextPath%>/images/query.gif",
				            handler:cmt
				        }
			    	]
			    });
			});
		</script>
	</head>
	<body onload="javascript:checkUsers()">
		<div id = "tbar" style="position:absolute;display:block left:0px; top:0px; width:100%; height:35px; z-index:1;"></div>
		<br>
		<div id="Layer" style="position:absolute;display:block left:0px; top:35px; width:100%; height:94%; z-index:1000; overflow:auto;">
		<form id="frmM"   name="frmM" method="POST" action="<%=contextPath%>/queryUser.do">
			<s:hidden name="bzdid"/>
			<s:hidden name="bzdname"/>
			<s:hidden name="organid"/>
			
			<table width="100%" id="contab">
				<tr>
					<th>
						用户帐号：
					</th>
					<td>
						<input type="text" onKeyPress="javascript:CheckKeyCodeCmt();" name="searchBean.con12" id="searchBean.con12" value="${searchBean.con12}"/>
					</td>
					<th>
						用户名称：
					</th>
					<td>
						<input type="text" onKeyPress="javascript:CheckKeyCodeCmt();" name="searchBean.con13" id="searchBean.con13" value="${searchBean.con13}"/>
					</td>
				</tr>
			</table>
			
			<hr>
			<table width="100%" id="listtab">
				<tr>
					<th width="25">
						<input name="chkAll" type="checkbox" id="chkAll"
							onclick="javascript:checkAll(this.form, 'id');" value="checkbox">
					</th>
					<th   width="100">帐号名称</th>
					<th   width="100">名称</th>
					<th   width="100">部门</th>
				</tr>

				<c:forEach items="${bzdList}" var="detail" >
					<tr>
						<td width="25" >
							<input type="checkbox" name="id" value="${detail.id}" />
						<br></td>
						<td  width="100">
							<a href="#" onClick="javascript:setParentOne('<c:out value="${detail.id}"/>','<c:out value="${detail.bzdname}"/>')" /><c:out value="${detail.loginid}"/></a><br>
						</td>
						<td id="id${detail.id}" style="display:none"><c:out value="${detail.id}"/></td>
						<td id="bzdname${detail.id}" style="display:none"><c:out value="${detail.bzdname}"/></td>
						<td  width="100" ><c:out value="${detail.bzdname}"/><br></td>
						<td  width="100" ><c:out value="${detail.organname}"/><br></td>
					</tr>
				</c:forEach>

				<c:if test="${bzdList == null || fn:length(bzdList) == 0 }">
					<tr>
						<td colspan="6" style="text-align: center">
							无相关记录
						</td>
					</tr>
				</c:if>
				
			</table>
		</form>
		</div>
	</body>
</html>
<script language="javascript">

			// 查询
			function cmt(){
				document.frmM.action = "<%=contextPath%>/bzdList!getUserListByRoleCode.do?page=1&c=c";
				document.frmM.submit();
			}
			
			function CheckKeyCodeCmt(){
				var keyCode = event.keyCode;
				if(keyCode==13){
					cmt();
					event.keyCode = null;
				}
			}
			
			// 单选设置父窗体短语
			function setParentOne(bzdid, bzdname) {
			
				try {
					window.opener.document.frmM.elements["${bzdname}"].value = bzdname;
					window.opener.document.frmM.elements["${bzdid}"].value = bzdid;
				} catch(e) {
					alert(e);
				}
				window.close();	
			}
			
			// 多选设置父窗体短语
			function setParentMany() {
			
				try {

					var idArray = getCheckValueMany("id").split(",");

					var bzdid = "";
					var bzdname = ""
					for (var i=0; i<idArray.length-1;i++) {
						bzdid += document.getElementById("id" + idArray[i]).innerHTML + ",";	
						bzdname += document.getElementById("bzdname" + idArray[i]).innerHTML + ",";	
					}
					
 					if (bzdid.endWith(",")) {
 						bzdid = bzdid.substring(0,bzdid.length-1);
 					}
 			
 					if (bzdname.endWith(",")) {
 						bzdname = bzdname.substring(0,bzdname.length-1);
 					}

					window.opener.document.frmM.elements["${bzdname}"].value = bzdname;
					window.opener.document.frmM.elements["${bzdid}"].value = bzdid;
					
				} catch(e) {
					alert(e);
				}
				window.close();	
			}
			
			function checkUsers() {
			
					var bzdid = window.opener.document.frmM.elements["${bzdid}"].value.split(",");
		
					for (var i = 0; i <document.frmM.elements.length; i++)
					{
						var e = document.frmM.elements[i];
						
						for (var j=0;j<bzdid.length;j++) {
	   						if (e.type == "checkbox" && e.value == bzdid[j]){
								e.checked = true;
								break;
							}
							
						}
					}
	
			}
		</script>